﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using LRSTaxServices.Biz;
using LRSTaxServices.Common;

public partial class Controls_ContactUsViewEdit : System.Web.UI.UserControl
{
    #region Constants

    private const string PROP_MODE = "__ContactUsViewEdit::Mode";

    #endregion

    #region Public Properties

    /// <summary>
    /// Gets / sets the ContactUs data source object.
    /// </summary>
    public ContactUs DataSourceContactUs
    {
        get
        {
            if (_dataSource == null)
            {
                if (DataSourceContactUsRequested != null)
                    DataSourceContactUsRequested(this, EventArgs.Empty);
            }
            return (_dataSource);
        }
        set
        {
            if (_dataSource != value)
            {
                _dataSource = value;
            }
        }
    } private ContactUs _dataSource = null;

    /// <summary>
    /// Gets / sets the control's mode.
    /// </summary>
    public ViewEditMode Mode
    {
        get { return (ViewState[ClientID + PROP_MODE] is ViewEditMode ? (ViewEditMode)ViewState[ClientID + PROP_MODE] : ViewEditMode.View); }
        private set { ViewState[ClientID + PROP_MODE] = value; }
    }

    #endregion

    #region Public Events

    public event EventHandler DataSourceContactUsRequested;

    #endregion

    #region Public Methods

    /// <summary>
    /// Method initializes and binds the controls UI elements to the properties of the specified object instance.
    /// </summary>
    public bool DataBind(ContactUs ContactUs)
    {
        return (DataBind(ContactUs, Mode));
    }


    /// <summary>
    /// Method initializes and binds the controls UI elements to the properties of the specified object instance.
    /// </summary>
    public bool DataBind(ContactUs ContactUs, ViewEditMode mode)
    {
        DataSourceContactUs = ContactUs;
        Mode = mode;

        SetLayout(Mode);

        UpdateData(UpdateDirection.Obj_To_UI);

        return (true);
    }


    /// <summary>
    /// Method causes the control to update its DataSource(s) with the values in the UI elements.
    /// </summary>
    public bool EndEdit()
    {
        UpdateData(UpdateDirection.UI_To_Obj);
        return (true);
    }


    /// <summary>
    /// Method causes the control to reject changes made in the UI by rebinding the UI elements to the DataSource(s).
    /// </summary>
    public void CancelEdit()
    {
        UpdateData(UpdateDirection.Obj_To_UI);
    }


    /// <summary>
    /// Method sets the control's ViewEditMode.
    /// </summary>
    public void SetViewEditMode(ViewEditMode mode)
    {
        Mode = mode;
        SetLayout(Mode);
    }

    #endregion

    #region Event Handlers

    #region Page Load

    protected void Page_Load(object sender, EventArgs evt)
    {
        if (!Page.IsPostBack)
        {
            //InitMaxFieldLengths();
        }
    }

    #endregion

    #endregion

    #region Privates

    #region SetLayout

    private void SetLayout(ViewEditMode mode)
    {
        switch (mode)
        {
            case ViewEditMode.View:
                break;

            case ViewEditMode.Edit:
                break;
        }
    }

    #endregion

    #region InitMaxFieldLengths

    private void InitMaxFieldLengths()
    {
        //Process to initialize the maxlenght values to the control on UI
    }

    //#endregion



    #endregion

    #region UpdateDate

    public void UpdateData(UpdateDirection updatedir)
    {
        if (DataSourceContactUs == null)
            return;

        bool addingNew = (DataSourceContactUs.ObjState == BOBase.ObjectState.Added);

        
        if (updatedir == UpdateDirection.Obj_To_UI)
        {
            //View Elements





            //Edit Elements
            lblfirstname.Text = DataSourceContactUs.FirstName;
            lbllastname.Text = DataSourceContactUs.LastName;           
            lblofficephone.Text = DataSourceContactUs.ContactPhone;
            lblemail.Text = DataSourceContactUs.EmailAddress;
            lbladdress1.Text = DataSourceContactUs.Address1;
            lbladdress2.Text = DataSourceContactUs.Address2;
            lblcity.Text = DataSourceContactUs.City;
            lblstate.Text = DataSourceContactUs.State;
            lblmessage.Text = DataSourceContactUs.Messages;
        }
        else
        {

        }

    }

    #endregion

    #endregion
}
